﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Caihongtu
{
    public partial class Statistic : Form
    {
        public Statistic()
        {
            InitializeComponent();
        }

        private void Statistic_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strline;
            string[] aryline;
            //string strNow = DateTime.Now.ToString("yyyyMM");
            if (Directory.Exists("E://Caihongtu") == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory("E://Caihongtu");
            }
            string strPath = "E:\\Caihongtu\\order";
            double dwPrice = 0;
            System.IO.StreamReader mysr = new System.IO.StreamReader(strPath, System.Text.Encoding.UTF8);
            string strDate = DateTime.Now.ToString("yyyy/MM/dd");
            while ((strline = mysr.ReadLine()) != null)
            {
                if (strline == "") continue;
                aryline = strline.Split(new char[] { ',' });
                if (aryline.Length != 3)
                    continue;
                Console.Write(aryline[0]);
                string str = aryline[0].Substring(0, 10);
                if (str.Equals(strDate))
                { 
                    dwPrice += double.Parse(aryline[1]);
                }
            }
            textBox1.Text = dwPrice.ToString();
            System.Console.WriteLine("Hello World!");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string strline;
            string[] aryline;
            //string strNow = DateTime.Now.ToString("yyyyMM");
            if (Directory.Exists("E://Caihongtu") == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory("E://Caihongtu");
            }
            string strPath = "E:\\Caihongtu\\order";
            double dwPrice = 0;
            System.IO.StreamReader mysr = new System.IO.StreamReader(strPath, System.Text.Encoding.UTF8);

            string strDate1 = dateTimePicker1.Value.ToString("yyyy/MM/dd");
            string strDate2 = dateTimePicker2.Value.ToString("yyyy/MM/dd");
            while ((strline = mysr.ReadLine()) != null)
            {
                if (strline == "") continue;
                aryline = strline.Split(new char[] { ',' });
                if (aryline.Length != 3)
                    continue;
                Console.Write(aryline[0]);
                string str = aryline[0].Substring(0, 10);
                if (str.CompareTo(strDate1) >= 0 && str.CompareTo(strDate2) <= 0 )
                {
                    if (comboBox1.Text == "所有" || comboBox1.Text == aryline[2])
                    { 
                        dwPrice += double.Parse(aryline[1]);
                    }
                }
            }
            textBox1.Text = dwPrice.ToString();
            System.Console.WriteLine("Hello World!");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string strline;
            string[] aryline;
            if (Directory.Exists("E://Caihongtu") == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory("E://Caihongtu");
            }
            string strPath = "E:\\Caihongtu\\order";
            double dwPrice = 0;
            System.IO.StreamReader mysr = new System.IO.StreamReader(strPath, System.Text.Encoding.UTF8);
            string strDate = DateTime.Now.ToString("yyyy/MM");
            while ((strline = mysr.ReadLine()) != null)
            {
                if (strline == "") continue;
                aryline = strline.Split(new char[] { ',' });
                if (aryline.Length != 3)
                    continue;
                Console.Write(aryline[0]);
                string str = aryline[0].Substring(0, 7);
                if (str.Equals(strDate))
                {
                    dwPrice += double.Parse(aryline[1]);
                }
            }
            textBox1.Text = dwPrice.ToString();
            System.Console.WriteLine("Hello World!");

        }
    }
}
